<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float: left;">
    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%; margin-top: 50px;"
      >
        <el-table-column align="center" width="150" prop="create_time" label="时间"/>
        <el-table-column
          align="center"
          prop="username"
          label="更改者"
          width="100"
        >
        </el-table-column>

        <el-table-column
          align="center"
          prop="key"
          label="更改字段"
          width="100"
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="description"
          label="字段内容"
        >
        </el-table-column>

         <el-table-column
          align="center"
          prop="old_value"
          label="原值"
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="value"
          label="新值"
        >
        </el-table-column>
        
        <el-table-column
          align="center"
          prop="telephone"
          fixed="right"
          width="100"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button size="small" type="primary" @click="update(scope.row)">还原</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import control from "../../components/control/control";
export default {
  name:'changeLog',
  components: { control },
  data() {
    return {
      config: [
        {
          type: "text",
          placeholder: "请输入关键字",
          field: "title",
          val: "",
        },
      ],
      value: "",
      searchWhere: {
        title: "",
      },
      tableData: [],
      fields: [],
      total: 0,
      current_page: 1,
      per_page: 14,
    };
  },
  mounted() {
    this.onSearch();
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch();
    },
    handleCurrentChange(val) {
      this.current_page = val;
      this.onSearch();
    },
    update(row){
      this.$msg_firm('确定要将:'+row.description+' 的值还原为:'+row.old_value+' 吗').then((e) => {
        this.get("/admin/Config/set_update", row,"POST").then((e) => {
          this.onSearch()
          this.$parent.$parent.onSearch()
        });
      })
    },
    onSearch() {
      const form = {};
      form.page = this.current_page;
      form.map = this.searchWhere;
      this.get("/admin/Config/get_log", form, "POST").then((e) => {
        this.fields = e.fields;
        this.tableData = e.list.data;
        this.per_page = e.list.per_page;
        this.total = e.list.total;
        this.current_page = e.list.current_page;
      });
    },
  },
};
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
